<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人所得税计算器</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        // 假设的个人所得税计算函数
        function calculateTax(income) {
            // 这里应包含实际的计算逻辑
            // 以下为示例税率和计算方法
            const taxRate = 0.1; // 假设税率为 10%
            const deductions = 5000; // 假设起征点为 5000 元
            const taxableIncome = Math.max(income - deductions, 0);
            return taxableIncome > 0 ? taxableIncome * taxRate : 0;
        }

        

        
        // 处理表单提交的函数
        function calculateTaxForm() {
            const income = document.getElementById('income').value;
           axios({
                url:'http://localhost:3000/calculate-tax',
                method:'POST',
                data:{
                    income,
                }
            }).then(res=>{
                // console.log(res);
                 tax = res.data.tax
                 alert('您的个人所得税为：' + tax.toFixed(2) + ' 元');
            return false; // 阻止表单默认提交行为
           
         })
          
        }
    </script>
</head>
<body>
    <h1>个人所得税计算器</h1>
    <form onsubmit="return calculateTaxForm()">
        <label for="income">请输入您的月收入：</label>
        <input type="number" id="income" name="income" required>
        <br><br>
        <button type="submit">计算税额</button>
    </form>
</body>
</html>